﻿using System;
using System.Collections.Generic;
using System.Text;
using SharpDiary.Core.Data;
using SharpDiary.Core.Utility;

namespace SharpDiary.Core.ORMapping
{
    /// <summary>
    /// 提醒类型。
    /// </summary>
    [TableInfoAttribute("ReminderStyle")]
    public class ReminderStyle : DbMappingObjectBase
    {
        #region Fields & Properties

        private Int64 _id = -1;

        [FieldMapping(true, System.Data.DbType.Int64, true, true)]
        public Int64 Id
        {
            get { return _id; }
            set { _id = value; }
        }

        private string _name = string.Empty;

        [FieldMapping(false, System.Data.DbType.String, false, false)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private string _description = string.Empty;

        [FieldMapping(false, System.Data.DbType.String, false, false)]
        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        private byte[] _picture = new byte[0];

        [FieldMapping(false, System.Data.DbType.Binary, false, false)]
        public byte[] Picture
        {
            get { return _picture; }
            set { _picture = value; }
        }

        private Int64 _dateStyle = 1;

        /// <summary>
        /// 日期类型。
        /// </summary>
        [FieldMapping(false, System.Data.DbType.Int64, false, false)]
        public Int64 DateStyle
        {
            get { return _dateStyle; }
            set { _dateStyle = value; }
        }

        #endregion

        #region Constructors

        public ReminderStyle() { }

        #endregion

        #region Methods

        /// <summary>
        /// 获取日期类型。
        /// </summary>
        /// <param name="dateStyle"></param>
        /// <returns></returns>
        public static DateStyle GetDateStyle(Int64 dateStyle)
        {
            return (DateStyle)dateStyle;
        }

        /// <summary>
        /// 获取指定编码的提醒类型信息。
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ReminderStyle GetReminderStyleById(Int64 id)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendLine("select * from ReminderStyle where Id = @id");

            DataAccessService das = Utils.GetDataAccessServiceInstance();
            return DbObjectMappingHelper.Query<ReminderStyle>(sql.ToString(),
                das.CreateParameter("@id", System.Data.DbType.Int64, id));
        }

        public override string ToString()
        {
            return (!string.IsNullOrEmpty(_name) ? _name : string.Empty);
        }

        #endregion
    }

    /// <summary>
    /// 日期类型。
    /// </summary>
    public enum DateStyle
    {
        /// <summary>
        /// 仅日期，不关心时间。
        /// </summary>
        Date = 0,

        /// <summary>
        /// 日期和时间
        /// </summary>
        DateAndTime = 1
    }
}
